package cn.yhbk.web.modules.manager.Controller;

import cn.yhbk.web.common.api.CommonResult;
import cn.yhbk.web.modules.manager.Pojo.Entity.TbGpaRecord;
import cn.yhbk.web.modules.manager.Pojo.VO.Apply.ApplyResp;
import cn.yhbk.web.modules.manager.Pojo.VO.OrderResponse;
import cn.yhbk.web.modules.manager.Pojo.VO.OrderResult.OrderParam;
import cn.yhbk.web.modules.manager.Service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.*;

@RestController
@Api(tags = "排行接口")
@RequestMapping("/manager/gpaOrder")
public class GpaOrderController {

    @Autowired
    private ITbStudentService studentService;

    @Autowired
    private ITbGpaRecordService recordService;

    @Autowired
    private ITbApplyService applyService;



    @ApiOperation("根据自定义集合获取排行")
    @PostMapping("/")
    public CommonResult getOrder(@RequestBody @Valid OrderParam param){


        List<Long> studentIds = studentService.getStuIdsByResultId(param.getResultId());
        List<OrderResponse> resList;

        if(Objects.isNull(param.getBursaryId())) resList = recordService.getRecordByStudentIds(studentIds);
        else resList = applyService.getOrderSortResponse(param.getResultId(), param.getBursaryId());

        return CommonResult.success("获取成功！",resList);

    }
}
